package com.example.administrator.printoutindemo.mvp.ui.view;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.printoutindemo.R;

import java.util.Calendar;

import cn.addapp.pickers.common.LineConfig;
import cn.addapp.pickers.picker.DateTimePicker;

/**
 * 属性选择的布局及逻辑
 */
public class RuKuRightSideslipLay extends RelativeLayout implements View.OnClickListener {
    private Context mCtx;
    private EditText et_ding_dan_hao;
    private EditText et_xiang_mu_ming_cheng;
    private EditText et_xiang_mu_bian_hao;
    private EditText et_wu_liao_ming_cheng;
    private EditText et_gong_ying_shang;


    private FlowingDrawerInterface mFlowingDrawerInterface;
    /**
     * 创建PopupWindow
     */
    private PopupWindow mMenuPop;
    private CloseMenuCallBack menuCallBack;
    private Activity mActivity;

    public RuKuRightSideslipLay(Context context, FlowingDrawerInterface flowingDrawerInterface, Activity activity) {
        super(context);
        mCtx = context;
        this.mFlowingDrawerInterface = flowingDrawerInterface;
        inflateView();
    }

    private void inflateView() {
        View view = View.inflate(getContext(), R.layout.fragment_menu_ru_ku, this);
        Toolbar toolbar = view.findViewById(R.id.toolbar);
        TextView tvTitle = toolbar.findViewById(R.id.title);

        Button btn_qu_xiao = view.findViewById(R.id.btn_qu_xiao);
        Button btn_que_ding = view.findViewById(R.id.btn_que_ding);
        et_ding_dan_hao = view.findViewById(R.id.et_ding_dan_hao);
        et_xiang_mu_ming_cheng = view.findViewById(R.id.et_xiang_mu_ming_cheng);
        et_xiang_mu_bian_hao = view.findViewById(R.id.et_xiang_mu_bian_hao);
        et_wu_liao_ming_cheng = view.findViewById(R.id.et_wu_liao_ming_cheng);
        et_gong_ying_shang = view.findViewById(R.id.et_gong_ying_shang);

        tvTitle.setText("筛选");
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mFlowingDrawerInterface.flowingDrawerClose();
            }
        });
        btn_qu_xiao.setOnClickListener(this);
        btn_que_ding.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_qu_xiao:
                mFlowingDrawerInterface.flowingDrawerClose();
                break;
            case R.id.btn_que_ding:
                String dingDanHao = et_ding_dan_hao.getText().toString().trim();
                String xiangMuMingCheng = et_xiang_mu_ming_cheng.getText().toString().trim();
                String xiangMuBianHao = et_xiang_mu_bian_hao.getText().toString().trim();
                String wuLiaoMingCheng = et_wu_liao_ming_cheng.getText().toString().trim();
                String gongYingShangMingCheng = et_gong_ying_shang.getText().toString().trim();
                mFlowingDrawerInterface.search(dingDanHao, xiangMuMingCheng, xiangMuBianHao, wuLiaoMingCheng, gongYingShangMingCheng, "", "");
                break;
        }
    }

    /***
     * 获取PopupWindow实例
     */
    private void getPopupWindow() {
        if (mMenuPop != null) {
            dismissMenuPop();
            return;
        } else {
        }
    }

    /**
     * 关闭窗口
     */
    private void dismissMenuPop() {
        if (mMenuPop != null) {
            mMenuPop.dismiss();
            mMenuPop = null;
        }

    }

    public void setCloseMenuCallBack(CloseMenuCallBack menuCallBack) {
        this.menuCallBack = menuCallBack;
    }

    public interface FlowingDrawerInterface {

        void flowingDrawerClose();

        void search(String dingDanHao, String xiangMuMingCheng, String xiangMuBianMa, String wuLiaoMingCheng, String gongYingShangMingCheng, String startTime, String endTime);

    }

    public interface CloseMenuCallBack {
        void setupCloseMean();
    }
}
